const express = require('express');
      router = express.Router();

// 判断用户名是否存在
// 友好url


app.post('/register',(req,res) => {
    //  req.body  --> 对象
    req.body.ip = req.ip
    req.body.time = new Date()
    
    var us = new User(req.body)
    us.save(function(err,data){
      send(res,'success','注册成功..')
    })
})

router.get('/username/:username',(req,res) => {
     var username = req.params.username
    //  console.log(username)
     User.find({username:username}).exec(function(err,data){
      //  console.log(Boolean(data[0]))
       var bool = Boolean(data[0])
       if(bool){
         send(res,'fail','已经存在该用户名，请重新注册··')
       }else{
         send(res,'success','用户名输入成功···')
       }

     })
    //  res.send({init:'666'})

})

router.get('/regist',(req,res) =>{
    res.render('user/register',{
      title:'注册',
      back:true
    })
})

module.exports = router